<?php
/**
 * @copyright  For copyright and license information, read the COPYING.txt file.
 * @link       /COPYING.txt
 * @license    Academic Free License (AFL 3.0)
 * @package     rwd_default
 */
?>
<?php /** @var Mage_Sales_Block_Billing_Agreement_View $this */ ?>
<div class="page-title title-buttons billing-agreement-view-header-wrapper">
    <h1 class="heading"><?php echo $this->__('Billing Agreement # %s', $this->escapeHtml($this->getReferenceId())) ?></h1>
    <?php if ($this->getCanCancel()): ?>
        <button type="button" title="<?php echo $this->quoteEscape($this->__('Cancel')) ?>" class="button" onclick="if( confirm('<?php echo $this->jsQuoteEscape($this->__('Are you sure you want to do this?')) ?>') ) { window.location.href = '<?php echo $this->getCancelUrl() ?>'; } return false;"><span><span><?php echo $this->__('Cancel') ?></span></span></button>
    <?php endif ?>
</div>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<div class="billing-agreements">
    <div class="info-box billing-agreement-details">
        <h2 class="box-title"><?php echo $this->__('Agreement Information') ?></h2>
        <div class="box-content">
            <table class="info-table">
                <tbody>
                <tr>
                    <th><?php echo $this->__('Reference ID:') ?></th>
                    <td><?php echo $this->escapeHtml($this->getReferenceId()); ?></td>
                </tr>
                <tr>
                    <th><?php echo $this->__('Status:') ?></th>
                    <td><?php echo $this->getAgreementStatus() ?></td>
                </tr>
                <tr>
                    <th><?php echo $this->__('Created:') ?></th>
                    <td><?php echo $this->escapeHtml($this->getAgreementCreatedAt()) ?></td>
                </tr>
                <?php if($this->getAgreementUpdatedAt()): ?>
                    <tr>
                        <th><?php echo $this->__('Updated:') ?></th>
                        <td><?php echo $this->escapeHtml($this->getAgreementUpdatedAt()); ?></td>
                    </tr>
                <?php endif ?>
                <tr>
                    <th><?php echo $this->__('Payment Method:') ?></th>
                    <td><?php echo $this->getPaymentMethodTitle() ?></td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <?php $relatedOrders = $this->getRelatedOrders() ?>
    <?php if(count($relatedOrders) > 0): ?>
        <?php echo $this->getChildHtml('pager'); ?>
        <h2 class="table-caption"><?php echo $this->__('Related Orders') ?></h2>
        <table class="data-table" id="related-orders-table">
            <col width="1" />
            <col width="1" />
            <col />
            <col width="1" />
            <col width="1" />
            <col width="1" />
            <thead>
            <tr>
                <th><span class="nobr"><?php echo $this->__('Order #') ?></span></th>
                <th><?php echo $this->__('Date') ?></th>
                <th><?php echo $this->__('Ship To') ?></th>
                <th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
                <th><span class="nobr"><?php echo $this->__('Order Status') ?></span></th>
                <th>&nbsp;</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($relatedOrders as $order): ?>
                <tr>
                    <td><?php echo $this->getOrderItemValue($order, 'order_increment_id') ?></td>
                    <td><span class="nobr"><?php echo $this->getOrderItemValue($order, 'created_at') ?></span></td>
                    <td><?php echo $this->getOrderItemValue($order, 'shipping_address') ?></td>
                    <td><?php echo $this->getOrderItemValue($order, 'order_total') ?></td>
                    <td><em><?php echo $this->getOrderItemValue($order, 'status_label') ?></em></td>
                    <td class="a-center">
                        <span class="nobr">
                            <a href="<?php echo $this->getOrderItemValue($order, 'view_url') ?>"><?php echo $this->__('View Order') ?></a>
                        </span>
                    </td>
                </tr>
            <?php endforeach ?>
            </tbody>
        </table>
        <script type="text/javascript">decorateTable('related-orders-table');</script>
    <?php endif ?>
    <div class="buttons-set">
        <p class="back-link"><a href="<?php echo $this->getBackUrl() ?>"><small>&laquo; </small><?php echo $this->__('Back to Billing Agreements') ?></a></p>
    </div>
</div>
